package cn.itcast.bos.service.trantis.Impl;

import cn.itcast.bos.Dao.trantis.InOutStorageInfoRepostiory;
import cn.itcast.bos.Dao.trantis.TrantisInfoRepostiory;
import cn.itcast.bos.domain.transit.InOutStorageInfo;
import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.service.trantis.InOutStorageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class InOutStorageInfoAerviceImpl implements InOutStorageInfoService {
    @Autowired
    private InOutStorageInfoRepostiory inOutStorageInfoRepostiory;
    @Autowired
    private TrantisInfoRepostiory trantisInfoRepostiory;
    @Override
    public void save(String transitInfoId, InOutStorageInfo model) {
        //保存
        inOutStorageInfoRepostiory.save(model);
        if (transitInfoId != null){
            TransitInfo transitInfo = trantisInfoRepostiory.findOne(Integer.parseInt(transitInfoId));
            transitInfo.getInOutStorageInfos().add(model);
            //更新状态
            if(model.getOperation().equals("到达网点")){
                transitInfo.setStatus("到达网点");
            }
            transitInfo.setOutletAddress(model.getAddress());
        }
    }
}
